﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Collections;
using Webchatting.Common;
using Webchatting.Dal;


public partial class server_AddGroupMum : System.Web.UI.Page
{
    public static ArrayList arrGroupIds = new ArrayList();
    public static ArrayList arrGroupNames = new ArrayList();
    public static ArrayList arrGroupDess = new ArrayList();
    public static ArrayList arrFRUIds = new ArrayList();
   // public static ArrayList arrFRURemarkNames = new ArrayList();
    public static ArrayList arrFRUNickNames = new ArrayList();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnListMyCreatedGroup_Click(object sender, EventArgs e)
    {
        FormsIdentity id = (FormsIdentity)User.Identity;
        OperationGroup Ogroup = new OperationGroup();
        string mygroup = Ogroup.LoadMyGroupDetails(id.Ticket.UserData.Split('@')[0],arrGroupIds,arrGroupNames,arrGroupDess);
        ltlResult.Visible = true;
        ltlText.Visible = true;

        ltlResult.Text = "<b>我创建的群：</b><br/>" + mygroup;
        ltlText.Text = "<b>请选择要操作的群ID：</b>";
        ddlSelectGroup.Visible = true;
        btnAddgroupMum.Visible = true;
        while (ddlSelectGroup.Items.Count > 0)
        {
            ddlSelectGroup.Items.RemoveAt(0);
        }

        for (int i = 0; i < arrGroupIds.Count; i++)
        {
            ddlSelectGroup.Items.Add(new ListItem((string)arrGroupIds[i], (string)arrGroupIds[i]));
        }


    }

    protected void btnAddgroupMum_Click(object sender, EventArgs e)
    {
        OperationFriends OFriend = new OperationFriends();
        FormsIdentity id = (FormsIdentity)User.Identity;
        string MyFriend = OFriend.GetFriendForGroup(id.Ticket.UserData.Split('@')[0], arrFRUIds, arrFRUNickNames);
        ltlText0.Visible = true;
        ltlResult0.Visible = true;
        ltlResult0.Text = "<b>我的好友：</b><br/>" + MyFriend;
        ltlText0.Text = "<b>请选择要添加的好友ID：</b>";
        btnAddgroupMumOne.Visible = true;
        btnAddgroupMumAll.Visible = true;

        ddlSelectFriend.Visible = true;
        while (ddlSelectFriend.Items.Count > 0)
        {
            ddlSelectFriend.Items.RemoveAt(0);
        }

        for (int i = 0; i < arrFRUIds.Count; i++)
        {
            ddlSelectFriend.Items.Add(new ListItem((string)arrFRUIds[i], (string)arrFRUIds[i]));
        }
    }
    protected void btnAddgroupMumOne_Click(object sender, EventArgs e)
    {
        OperationGroup Ogroup = new OperationGroup();
        int selected0 = ddlSelectGroup.SelectedIndex;
        int selected = ddlSelectFriend.SelectedIndex;
        FormsIdentity id = (FormsIdentity)User.Identity;

        try
        {


            Ogroup.AddGroupMum(arrGroupIds[selected0].ToString(),arrFRUIds[selected].ToString(),arrFRUNickNames[selected].ToString());
            Response.Write("<script>alert('添加群成员成功!');window.parent.location.href='AddGroupMum.aspx';</script>");
        }
        catch
        {
            Javascript.GoHistory(-1, "添加失败", Page);
        }

    }
    protected void btnAddgroupMumAll_Click(object sender, EventArgs e)
    {
        OperationGroup Ogroup = new OperationGroup();
        int selected0 = ddlSelectGroup.SelectedIndex;
        FormsIdentity id = (FormsIdentity)User.Identity;
       

        try
        {


            for (int i = 0; i < arrFRUIds.Count; i++)
            {
                Ogroup.AddGroupMum(arrGroupIds[selected0].ToString(), arrFRUIds[i].ToString(), arrFRUNickNames[i].ToString());
            }
            Response.Write("<script>alert('添加群成员成功!');window.parent.location.href='AddGroupMum.aspx';</script>");
        }
        catch
        {
            Javascript.GoHistory(-1, "添加失败", Page);
        }
    }
}
